﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using ESN.Models;
using System.Data.Entity;

namespace ESN
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{resource}.svc/{*pathInfo}");


            routes.MapRoute(
                "Apps",
                "Apps/{name}",
                new { controller = "Apps", action = "ShowApp"}
            );

            routes.MapRoute(
                "UserHome",
                "{name}/Home",
                new { controller = "Home", action = "UserHome" }
            );

            routes.MapRoute(
                "UserSetting",
                "{name}/Settings",
                new { controller = "Home", action = "UserSetting" }
            );

            routes.MapRoute(
                "UserGroup",
                "{name}/Groups",
                new { controller = "Home", action = "MyGroups" }
            );

            routes.MapRoute(
                "UserNoitce",
                "{name}/Notices",
                new { controller = "Home", action = "MyNotices" }
            );

            routes.MapRoute(
                "UserFriendRequest",
                "{name}/Requests",
                new { controller = "Home", action = "MyFriendRequests" }
            );

            routes.MapRoute(
                "UserFriendList",
                "{name}/Friends",
                new { controller = "Home", action = "FriendList" }
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            //Database.SetInitializer<ESNCoreDbContext>(new CreateDatabaseIfNotExists<ESNCoreDbContext>());
            //Database.SetInitializer<ESNQuizDbContext>(new CreateDatabaseIfNotExists<ESNQuizDbContext>());
            //Database.SetInitializer<ESNShareDbContext>(new CreateDatabaseIfNotExists<ESNShareDbContext>());
            ////DropCreateDatabaseIfModelChanges
            //Database.SetInitializer<ESNCoreDbContext>(new DropCreateDatabaseIfModelChanges<ESNCoreDbContext>());
            //Database.SetInitializer<ESNQuizDbContext>(new DropCreateDatabaseIfModelChanges<ESNQuizDbContext>());
            //Database.SetInitializer<ESNShareDbContext>(new DropCreateDatabaseIfModelChanges<ESNShareDbContext>());

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}